$(function() {
		
	// 定义列
	var columns = [
		{
				field : 'no',
				title : '序号',
				align : 'left',
				formatter : function(value, row, index) {
					return index + 1;
				}
		},
		{
				field : 'id',
				title : 'ID',
				align : 'center'
		},
		{
				field : 'orderCode',
				title : '订单编号',
				align : 'center'
		},
		{
				field : 'compnayName',
				title : '单位名称',
				align : 'center'
		},
		{
				field : 'taxNo',
				title : '税号',
				align : 'center'
		},
		{
				field : 'registeAddress',
				title : '注册地址',
				align : 'center'
		},
		{
				field : 'registePhone',
				title : '注册电话',
				align : 'center'
		},
		{
				field : 'openBankName',
				title : '开户银行',
				align : 'center'
		},
		{
				field : 'bankAccount',
				title : '银行账号',
				align : 'center'
		},
		{	
			field : '#',
			title : '操作',
			align : 'center',
			formatter : function(value, row, index) {
				if (row.status == "0") {
					return "<a href='javaScript:void(0);'onclick='updateStatus("
								+ row.id
								+ ","
								+ row.status
								+ ")'>启用</a>"
								+ "<a href='javaScript:void(0);'onclick='toEdit("
								+ row.id + ")'>编辑</a>";
				} else if (row.status == "1") {
					return "<a href='javaScript:void(0);'onclick='updateStatus("
								+ row.id
								+ ","
								+ row.status
								+ ")'>停用</a>"
								+ "<a href='javaScript:void(0);'onclick='toEdit("
								+ row.id + ")'>编辑</a>";
				}
			}
		}, ];
			
			
	// 定义查询回调函数（查询参数在此设置）
	var queryParams = function(params) {
	
		var id =  $("#id").val()
		var orderCode =  $("#orderCode").val()
		var compnayName =  $("#compnayName").val()
		var taxNo =  $("#taxNo").val()
		var registeAddress =  $("#registeAddress").val()
		var registePhone =  $("#registePhone").val()
		var openBankName =  $("#openBankName").val()
		var bankAccount =  $("#bankAccount").val()
		
		return {
			rows : params.limit, // 页面大小
			page : params.pageNumber, // 页码
			id : id,
			orderCode : orderCode,
			compnayName : compnayName,
			taxNo : taxNo,
			registeAddress : registeAddress,
			registePhone : registePhone,
			openBankName : openBankName,
			bankAccount : bankAccount
		};
	};
	
	var url = rootPath + "/orderInvoice/listOrderInvoicePage"; // 请求json数据的服务器地址
	sys.initTable('orderInvoiceTable', {
		url : url,
		queryParams : queryParams,
		columns : columns,
		striped : true,
		clickToSelect : true
	});

	// 查询
	$('#btnQuery').on('click', function() {
		sys.reloadTable('orderInvoiceTable');
	});
	
	// 清空
	$('#btnClear').on('click', function() {
		$("#id").val("");
		$("#orderCode").val("");
		$("#compnayName").val("");
		$("#taxNo").val("");
		$("#registeAddress").val("");
		$("#registePhone").val("");
		$("#openBankName").val("");
		$("#bankAccount").val("");
	});

	$('#btnAdd').on('click', function() {
		sys.showRemote(rootPath + '/orderInvoice/toAddOrderInvoice', function() {
			var key = sys.dialog.getData("key");
			if (key == '1') {
				showSuccess("添加成功！", sys.reloadTable('orderInvoiceTable'));
			} else if (key == '0') {
				showErr("添加失败！");
			}
		}, {
			title : '新增订单发票信息',
			width : 600,
			height : 600
		});

	});

})

// 跳转编辑页面
function toEdit(id) {
	window.location.href = rootPath + "/orderInvoice/toUpdateOrderInvoice?id=" + id;
}